#pragma once

#include <iostream>
#include "Protocol.hpp"

class Calculator
{
public:
    Calculator()
    {
    }
    Response Execute(Request &req)
    {
        // 拿到的都是结构化的数据
        Response resp;
        switch (req.Oper())
        {
        case '+':
            resp.SetResult(req.X() + req.Y());
            break;
        case '-':
            resp.SetResult(req.X() - req.Y());
            break;
        case '*':
            resp.SetResult(req.X() * req.Y());
            break;
        case '/':
        {
            if (req.Y() == 0)
            {
                resp.SetCode((int)ErrorCode::DivideByZero);
            }
            else
            {
                resp.SetResult(req.X() / req.Y());
            }
            break;
        }
        case '%':
        {
            if (req.Y() == 0)
            {
                resp.SetCode((int)ErrorCode::ModByZero);
            }
            else
            {
                resp.SetResult(req.X() % req.Y());
            }
            break;
        default:
                resp.SetCode((int)ErrorCode::UnknownError);
            break;
        }
        };
        return resp;
    }

    ~Calculator()
    {
    }

private:
};